package me.frank.mail.demo;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.stream.IntStream;

/**
 * @author Frank Wang
 * @Description:
 * @date 2018/8/21 13:51
 */
@Service
public class AsyncService {
    Random random=new Random();
    @Async
    public synchronized void printf(Integer i) {
        final long start = System.currentTimeMillis();
        final int i1 = random.nextInt(10000);

        try {
            Thread.sleep(i1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
            System.out.println("线程"+Thread.currentThread().getId()+"正在执行计算任务..."+i);
            final long end = System.currentTimeMillis();
            System.err.println("线程"+Thread.currentThread().getId()+"计算结束"+i+"任务耗时:"+(end-start));

    }
}
